package com.fizzkai.p2p.mgrsite.interceptor;

import com.fizzkai.p2p.core.util.UserContext;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * 拦截器
 */
public class CheckLoginInterceptor extends HandlerInterceptorAdapter {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // 判断 session 中 是否有 session 对象
//        System.out.println("-------------------华丽分割线----------------------");
//        System.out.println(handler);
//        System.out.println(handler.getClass());
//        System.out.println("-------------------另外で一条，华丽の分割线----------------------");
        if (UserContext.getCurrentLoginInfo() == null) {
            // 如果没有 跳转 登陆界面
            response.sendRedirect("/login.html");
            return false;
        }
        return true;
    }
}
